package jar

object ClosureTest {


  def main(args: Array[String]): Unit = {

    println("闭包外部变量变值前："+myClosureFunction(4))

    outerVar=4

    println("闭包外部变量变值后："+myClosureFunction(4))

    var stringArray :Array[String]=new Array[String](3)

    stringArray(0)="hello"
    stringArray(1)=","
    stringArray(2)="world"

    var i=0

    for(str <- stringArray){
      i=i+1
      println("item"+i+":"+str)
    }


    listTestFunction()

  }

  var outerVar:Int = 3;

  var myClosureFunction= (i:Int) => i*outerVar



  var listTestFunction = ()=>{

    var site:List[String] =List("hello",",","world")


    var nums:List[Int] = List(1,2,3)

    var empty:List[Unit] =List()


    var twoDimList:List[List[String]] =
      List(
        List("hello",",","world"),
        List("你好",",","世界")
      )


    site="hello"::(","::("world"::Nil))


    println("list first item :"+site.head)

    println("list last item :"+site.tail+" 第2个元素"+site(2))

    println("list is empty :"+site.isEmpty)


    println(site.exists(x=>x.equals("hello")))

  }


}
